/**
 * 文章子路由
 */
const express = require('express');
// 导航类目中间件
const category = require('../middleware/category');
// 文章中间件
const article = require('../middleware/article');
// 权限中间件，获取用户信息
const auth = require('../middleware/auth');
// 文章子应用
const articleApp = express();

articleApp.use(category.getList);
articleApp.use(auth.getUser);

// 文章列表页
articleApp.get('/list/:id',[category.getCategoryId,article.getListCategoryId],(req,res)=>{
    let {category,articles,categoryId,user} = req;
    res.render('list',{category,articles,categoryId,user});
});
// 文章详情页
articleApp.get('/:id',[article.getArticleById,article.getTabs,article.getPrevArticle,article.getNextArticle],(req,res)=>{
    // prev 上一页数据，next 下一页数据
    let {category,articles,tabs,prev,next,user} = req;
    res.render('article',{category,articles,tabs,prev,next,user});
});
module.exports = articleApp;